// packageC/pages/packCard/packCard.js
var common = require("../../../public.js");
const QRCode = require('../../../utils/weapp-qrcodes.js')
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabbarActive:3,
        isShow:false,
        isOverShare:true   //全局分享标识请勿删除
    },

    /**
     * 生命周期函数--监听页面加载
     */
    // 更多会员卡
    click_moreCard(){
        let url = '/packageC/pages/morePackCard/morePackCard?title=更多会员卡'
        common.tiao_Zhuan(url)
    },
    // 跳转会员卡页面
    toYear(e){
        var obj = e.currentTarget.dataset.item
        console.log('obj--',obj);
         var objs =JSON.stringify(obj) 
        wx.navigateTo({
          url:'/packageA/pages/indexnian/indexni?obj=' + encodeURIComponent(objs),
        })
    },
    toIndex(){
      wx.redirectTo({
        url: '/packageA/pages/indexnian/indexni',
      })  
    },
    toOrder() {
        wx.redirectTo({
            url: '/pages/ScenicArea/NianCardOrder/index',
        })
    },
    onLoad: function (options) {
        var that = this
        //  获取个人信息
        common.getLocalUserInfo(function (success, data) {
            if (success) {
                that.setData({
                    userInfo: data.user,
                    token: data.token
                }, function () {
                    this.cardsList() //会员卡列表
                })
            } else {
                that.setData({
                    userInfo: null,
                    token: '',
                })
            }
        }, true)

    },
    // 我购买会员卡列表接口-------------------------------------------------------------------------------
    cardsList() {
        var that = this
        common.get('/userAnnualCard/getUserCardProductList', {
            userId: that.data.userInfo.id,
            token: that.data.token
        }, res => {
            if (res.status === 200) {
                for (var i = 0; i < res.data.length; i++) {
                    res.data[i].validTime = that.time(res.data[i].validTime)
                }
                that.setData({
                    nianList: res.data
                }, () => {
                    if (that.data.nianList.length) {
                        // that.typeList(that.data.nianList[0].annualCardId) //轮播第一条数据
                        that.setData({
                            id: that.data.nianList[0].annualCardId,
                            times: that.data.nianList[0].validTime,
                            cardImage: that.data.nianList[0].cardImage,
                            merchantPhone: that.data.nianList[0].merchantPhone,
                        }, () => {
                            // that.Nian_ca()
                        })
                    }
                })
            } else {
                common.showRequestErrMsg(res)
            }
        })
    },
    // 时间戳
    time(time) {
        return common.dateFormat('yyyy-MM-dd', time)
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
          title: '飞羊精选',
          path: 'packageC/pages/packCard/packCard',
          imageUrl: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/yearCard/year_cardshare.jpg',
          success: (res) => {},
          fail: (res) => {
            // 分享失败
          }
        }
      },
      onShareTimeline() {
        return {
          title: '飞羊精选',
          path: 'packageC/pages/packCard/packCard',
          imageUrl: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/yearCard/year_cardshare.jpg',
          success: (res) => {},
          fail: (res) => {
            // 分享失败
          }
        }
      }
})